@include('admin.public.head')
@include('admin.public.pop')
@include('admin.public.laydate')
<link href="{{ URL::asset('./admin/css/class_base.css') }}" rel="stylesheet">

<div class="ibox-title" style="border: 0px">
    <h5>課程添加 &nbsp;&nbsp;</h5></br></br>
    <h5>@if(isset($home)) 安排课室编号：{{$home['classroom_nubering']}} 安排時間：{{$home['base_time']['week_name']}}&nbsp;&nbsp;{{$time}}@endif</h5>
    </br>
    <div class="class_base">
        <h5>已设置 &nbsp;&nbsp;</h5></br></br>
        @foreach($booked as $v)
        <p>
            上課季度：{{$v['quarterly']['name']}}</br>
            時段：{{$v['class_time']['time_start']}}~{{$v['class_time']['time_end']}}</br>
            指定時間上課：{{$v['designated_date']}}</br>
            教室：{{$v['classsroom']['numbering']}}</br>
            教師：{{$v['teacher']['teacher_name']}}</br>
            課程：{{$v['class_base']['class_name']}}</br>
        </p>
        @endforeach
    </div>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">

        <div class="form-group">
            <label class="col-sm-3 control-label">指定上课时间：</label>
            <div class="col-sm-3">
                <textarea class="layui-textarea laydate-test-area" name="designated_date" rows="5" >{{$reservation_lists['designated_date']??''}}</textarea>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        @if(isset($id))
        <div class="form-group">
            <label class="col-sm-3 control-label">上课老师：</label>
            <div class="col-sm-3">
                <a href="javascript:void(0)" class="btn btn-primary" onclick="toggle_info($(this),'80%','80%')" url="/class_base_info_teacher/{{$id}}">安排</a>
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        @else
        <div class="form-group">
            <label class="col-sm-3 control-label">上课老师：</label>
            <div class="col-sm-3">
                <select class="form-control" name="teacher_id" >
                    <option value="" >请选择老师</option>
                    @foreach($teacher_id as $k=>$v)
                        <option value="{{$v->id}}" >{{$v->teacher_name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        @endif

        <div class="form-group">
            <label class="col-sm-3 control-label">上课周期：</label>
            <div class="col-sm-3">
                <select class="form-control" name="week" disabled>
                    <option value="" >请选择周期</option>
                    @foreach($week_lists as $k=>$v)
                        <option value="{{$k}}" @if($k == $home['base_time']['week']) selected @endif>{{$v}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上課季度：</label>
            <div class="col-sm-3">
                <select class="form-control" name="class_quarterly_id">
                    <option value="" >请选择上課季度</option>
                    @foreach($class_quarterly as $k=>$v)
                        <option value="{{$v->id}}" @if(isset($id)) @if($reservation_lists['class_quarterly_id'] == $v->id) selected @endif @endif>{{$v->name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上课开始时间</label>
            <div class="col-sm-3">
                <select class="form-control" name="start_hour" id="startHour" @if(isset($id)) disabled @endif>
                    <option value=""></option>
                </select>
            </div>

            <div class="col-sm-3">
                <select class="form-control" name="start_minute" id="startMinute" @if(isset($id)) disabled @endif>
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上课结束时间</label>
            <div class="col-sm-3">
                <select class="form-control" name="end_hour" id="endHour" @if(isset($id)) disabled @endif>
                    <option value=""></option>
                </select>
            </div>

            <div class="col-sm-3">
                <select class="form-control" name="end_minute" id="endMinute" @if(isset($id)) disabled @endif>
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">門店分類：</label>
            <div class="col-sm-3">
                <select class="form-control" name="store_id" id="store_id" disabled>
                    <option value="" >請選擇門店</option>
                    @foreach($select_store as $k=>$v)
                        <option value="{{$k}}" @if($store_id == $k) selected="selected" @endif>{{$v}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課程編號：</label>
            <div class="col-sm-3">
                <select class="form-control" name="class_base_numbering_id" id="class_base_numbering_id">
                    <option value="" >請選擇課程編號</option>
                    @foreach($select_class_base_numbering as $k=>$v)
                        <option value="{{$v->id}}" @if($class_base_numbering_id == $v->id) selected="selected" @endif>{{$v->numbering}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課程名稱：</label>
            <div class="col-sm-3 text-center">
                <select class="form-control" name="class_base" >

                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課室：</label>
            <div class="col-sm-3 text-center">
                <select class="form-control" name="classroom" disabled>

                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">允許多少分鐘前取消預約：</label>
            <div class="col-sm-3">
                <input type="number" name="advance_cancel_time" class="form-control" placeholder="允許多少分鐘前取消預約" value="{{$reservation_lists['advance_cancel_time']??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上課人數：</label>
            <div class="col-sm-3">
                <input type="number" name="class_number_people" class="form-control" placeholder="上課人數" value="{{$reservation_lists['class_number_people']??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">最少上課人數：</label>
            <div class="col-sm-3">
                <input type="number" name="minimum_number" class="form-control" placeholder="最少上課人數" value="{{$reservation_lists['minimum_number']??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">提前檢測是否夠人開課時間(分)：</label>
            <div class="col-sm-3">
                <input type="number" name="start_before_minutes" class="form-control" placeholder="多少分钟" value="{{$reservation_lists['start_before_minutes']??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">是否camp：</label>
            <div class="col-sm-9">
                <label value="1">
                    <input type="radio" name="is_camp"  value="1" @if(isset($id)) @if($reservation_lists['is_camp'] == '1') checked="checked" @endif @else @endif @if(isset($id)) disabled @endif>是
                </label>
                <label value="0">
                    <input type="radio" name="is_camp"  value="2" @if(isset($id)) @if($reservation_lists['is_camp'] == '2') checked="checked"  @endif @else @endif @if(isset($id)) disabled @endif>否
                </label>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">全部周期预约控制：</label>
            <div class="col-sm-9">
                <label value="1">
                    <input type="radio" name="is_display" value="1" @if(isset($id)) @if($reservation_lists['is_display'] == '1') checked="checked" @endif @endif>开放
                </label>
                <label value="0">
                    <input type="radio" name="is_display" value="-1"  @if(isset($id)) @if($reservation_lists['is_display'] == '-1') checked="checked" @endif @else checked="checked" @endif>关闭
                </label>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">当前时间预约控制：</label>
            <div class="col-sm-9">
                <label value="1">
                    <input type="radio" name="open_an_appointment" value="1" @if(isset($id)) @if($open_an_appointment == '1') checked="checked" @endif @endif>开放
                </label>
                <label value="0">
                    <input type="radio" name="open_an_appointment" value="-1"  @if(isset($id)) @if($open_an_appointment == '-1') checked="checked" @endif @else checked="checked" @endif>关闭
                </label>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <input type="hidden" name="id" value="{{$id??0}}">
                <a href="javascript:void(0)" class="btn btn-primary do" type="submit">操作</a>
            </div>
        </div>
    </form>
</div>

<script>

    $('.do').click(function(){
        var form = new FormData();

        var time = "{{$time}}";

        var week = $('select[name="week"] option:selected').val();
        var class_quarterly_id = $('select[name="class_quarterly_id"] option:selected').val();

        var start_hour = $('select[name="start_hour"] option:selected').val();
        var start_minute = $('select[name="start_minute"] option:selected').val();
        var end_hour = $('select[name="end_hour"] option:selected').val();
        var end_minute = $('select[name="end_minute"] option:selected').val();

        var teacher_id = $('select[name="teacher_id"] option:selected').val();

        var start_string = start_hour+":"+start_minute;
        var end_string = end_hour+":"+end_minute;

        var id = $('input[name="id"]').val();
        var designated_date = $('textarea[name="designated_date"]').val();
        var advance_cancel_time = $('input[name="advance_cancel_time"]').val();
        var class_number_people = $('input[name="class_number_people"]').val();
        var minimum_number = $('input[name="minimum_number"]').val();
        var start_before_minutes = $('input[name="start_before_minutes"]').val();
        var is_camp = $('input[name="is_camp"]:checked').val();
        var is_display = $('input[name="is_display"]:checked').val();
        var open_an_appointment = $('input[name="open_an_appointment"]:checked').val();

        if(typeof(is_camp) == 'undefined')is_camp = '';
        if(typeof(is_display) == 'undefined')is_display = '';

        if(designated_date != '' && is_camp == 1){
            var swal_json = {
                title: 'camp不能指定日期显示',
                type: "error"
            }

            swal(swal_json, function (isConfirm) {

            });

            return false;
        }

        var store_id = $('select[name="store_id"] option:selected').val();
        var class_base_id = $('select[name="class_base"] option:selected').val();
        var classroom_id = $('select[name="classroom"] option:selected').val();

        form.append("start_hour", start_hour);
        form.append("teacher_id", teacher_id);
        form.append("start_minute", start_minute);
        form.append("end_hour", end_hour);
        form.append("end_minute", end_minute);
        form.append("designated_date", designated_date);

        form.append("class_week", week);
        form.append("class_quarterly_id", class_quarterly_id);
        form.append("class_base_id", class_base_id);
        form.append("advance_cancel_time", advance_cancel_time);
        form.append("class_time", start_string+"~"+end_string);
        form.append("start_string", start_string);
        form.append("end_string", end_string);
        form.append("class_number_people", class_number_people);
        form.append("start_before_minutes", start_before_minutes);
        form.append("minimum_number", minimum_number);
        form.append("store_id", store_id);
        form.append("class_classroom_id", classroom_id);
        form.append("is_camp", is_camp);
        form.append("is_display", is_display);
        form.append("open_an_appointment", open_an_appointment);
        form.append("time", time);
        form.append("id", id);

        $.ajax({
            type: 'POST',
            url: '/class_base_info_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });

    var time_start_hour = "{{$time_start_hour??''}}";
    var time_start_minute = "{{$time_start_minute??''}}";
    var time_end_hour = "{{$time_end_hour??''}}";
    var time_end_minute = "{{$time_end_minute??''}}";

    getTime();

    function getTime() {

        var start_html = "<option value=''>时</option>";
        var end_html = "<option value=''>时</option>";

        for (var i = 0; i < 24; i++) {

            if (i < 10) {
                start_html += "<option value='" + '0' + i + "' ";

                var option_select = '0'+i;

                if(option_select == time_start_hour) start_html += "selected='selected'";

                start_html += ">" + '0' + i + "</option>";
            } else {
                start_html += "<option value='" + i + "'";

                if(i == time_start_hour)start_html += "selected='selected'";

                start_html += ">" + i + "</option>";
            }

            if (i < 10) {
                end_html += "<option value='" + '0' + i + "' ";

                var option_select = '0'+i;

                if(option_select == time_end_hour)end_html += "selected='selected'";

                end_html += ">" + '0' + i + "</option>";
            } else {
                end_html += "<option value='" + i + "'";

                if(i == time_end_hour)end_html += "selected='selected'";

                end_html += ">" + i + "</option>";
            }

        }

        $('#startHour').html(start_html);
        $('#endHour').html(end_html);

        var start_html = "<option value=''>分</option>";
        var option_select = '';

        for (var i = 0; i < 60; i++) {
            if (i < 10) {
                start_html += "<option value='" + '0' + i + "' ";

                var option_select = '0'+i;

                if(option_select == time_start_minute)start_html += "selected='selected'";

                start_html += ">" + '0' + i + "</option>";
            } else {
                start_html += "<option value='" + i + "' ";

                if(i == time_start_minute)start_html += "selected='selected'";

                start_html += ">" + i + "</option>";
            }
        }

        var end_html = "<option value=''>分</option>";
        var option_select = '';

        for (var i = 0; i < 60; i++) {
            if (i < 10) {
                end_html += "<option value='" + '0' + i + "' ";

                var option_select = '0'+i;

                if(option_select == time_end_minute)end_html += "selected='selected'";

                end_html += ">" + '0' + i + "</option>";
            } else {
                end_html += "<option value='" + i + "' ";

                if(i == time_end_minute)end_html += "selected='selected'";

                end_html += ">" + i + "</option>";
            }
        }


        $('#startMinute').html(start_html);
        $('#endMinute').html(end_html);

    }
</script>

<script>
    var class_base_id = "{{$class_base_id??0}}";
    var teacher_id = "{{$teacher_id??0}}";
    var classroom_id = "{{$classroom_id??0}}";
    var base_time_id = "{{$base_time_id??0}}";
    var week_id =  $("select[name='week'] option:selected").val();
</script>

<script type="text/javascript" src="{{ URL::asset('./admin/js/reservation/classroom_teacher_classbase.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('./admin/js/reservation/class_base_time.js') }}"></script>

